package com.briup.app03.web.controller;

import com.briup.app03.bean.UserInfo;
import com.briup.app03.service.IUserInfoService;
import com.briup.app03.utils.Message;
import com.briup.app03.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author pete
 * @version 1.0
 * @date 2020/12/15 21:11
 */
@RestController
@Validated
@RequestMapping("/UserInfo")
public class UserInfoController {
    @Autowired
    private IUserInfoService userInfoService;

    @GetMapping("query")
    public Message query(String realname, String gender){
        List<UserInfo> list = userInfoService.query(realname, gender);
        return MessageUtil.success(list);
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(UserInfo info){
        userInfoService.saveOrUpdate(info);
        return MessageUtil.success("操作成功");
    }

    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value="用户编号",required =true, paramType = "query"),
    })
    public Message deleteById(@NotNull Long id){
        userInfoService.deleteById(id);
        return MessageUtil.success("操作成功");
    }
}
